<?php

namespace app\http\middleware;

use app\admin\model\ActionLog;
use app\admin\service\ActionLogService;
use Throwable;

class RecordLog
{
    /**
     * @throws Throwable
     */
    public function handle($request, \Closure $next)
    {
        try {
            $response = $next($request);
            ActionLogService::record($request, $response);
        } catch (Throwable $exception) {
            ActionLogService::record($request, $exception);
            throw $exception;
        }

        return $response;
    }
}
